package org.example.mall.Controller;

import org.example.mall.Mapper.ConsigneeInfoMapper;
import org.example.mall.Pojo.ConsigneeInfo;
import org.example.mall.Pojo.Result;
import org.example.mall.Service.ConsigneeInfoService;
import org.example.mall.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/consignee")
public class ConsigneeInfoController {
    @Autowired
    private ConsigneeInfoService cService;

    @PostMapping("/new")
    void createConsignee(@RequestBody ConsigneeInfo consignee) {
        Map<String, Object> map = ThreadLocalUtil.get();
        String username = map.get("username").toString();
//        String username = "user02";
        cService.createConsignee(username, consignee.getConsigneeName(), consignee.getConsigneePhone(), consignee.getConsigneeAddress());
    }

    @GetMapping("/consigneeList")
    List<ConsigneeInfo> getConsigneeList() {
        Map<String, Object> map = ThreadLocalUtil.get();
        String userName = map.get("username").toString();
//        String userName = "user02";
        return cService.getConsigneeListByUserName(userName);
    }
    @GetMapping("/consigneebycid")
    ConsigneeInfo getConsigneeByCId(@RequestParam("cid") Integer cId) {
        return cService.getConsigneeByCId(cId);
    }

    @GetMapping("/delete")
    void deleteConsignee(@RequestParam("cid") Integer cId) {
        cService.updateToNoUserNameConsignee(cId);
//        cService.deleteConsignee(cId);
    }
}
